package top.eggcode.modules.dict.store;

import org.springframework.stereotype.Repository;
import top.eggcode.component.query.CriteriaBuilder;
import top.eggcode.component.query.model.PageList;
import top.eggcode.modules.dict.model.DictEntity;
import top.eggcode.modules.dict.model.DictQuery;

import javax.annotation.Resource;

/**
 * Title:
 * Description: TODO
 * Date: 2021/9/19 11:27
 *
 * @author JiaQi Ding
 * @version 1.0
 */
@Repository
public class DictStore {
    @Resource
    private CriteriaBuilder builder;

    public PageList<DictEntity> page(DictQuery query) {
        return builder.createQuery(DictEntity.class)
                .select("*")
                .fromEntity()
                .where(condition -> {
                    if (query.getName() != null) {
                        condition
                                .likeAny("name", query.getName())
                                .or()
                                .likeAny("code", query.getCode());
                    }
                })
                .fetchPage(query);
    }

}
